package com.wcc.mpmultidb.controller;

import com.alibaba.fastjson.JSON;
import com.wcc.mpmultidb.common.CommonResult;
import com.wcc.mpmultidb.entity.User;
import com.wcc.mpmultidb.service.MasterUserService;
import com.wcc.mpmultidb.service.SlaveUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuch
 * @version 1.0
 * @date 2021/4/9 9:39
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户服务",description = "用户相关服务")
@CrossOrigin
public class UserController {

    @Autowired
    private MasterUserService masterUserService;

    @Autowired
    private SlaveUserService slaveUserService;

    /**
     * 获取用户根据id
     * @return
     */
    @ApiOperation(value = "获取用户根据id", notes = "查询用户")
    @GetMapping("getUserById")
    public CommonResult<User> getUserById(String id){
        User user = masterUserService.getById(id);
        int i = 1/0;
        return CommonResult.success(user);
    }

    /**
     * 添加用户
     * @return
     */
    @ApiOperation(value = "添加用户", notes = "从库添加用户")
    @PostMapping("add")
    public CommonResult<Boolean> addUser(@RequestBody User user){
        return CommonResult.success(slaveUserService.save(user));
    }
}
